
/**
 * Created with IntelliJ IDEA.
 * Description: 模拟银行操作,调用方法进行存取款等操作
 * User: 86183
 * Date: 2022-09-29
 * Time: 10:45
 */
class Bank {
    //定义公成员方变量
    public String name;
    public double balance;
    public double moneys;
    public String password = "123456";
    //定义一个静态的成员变量
    static String bankname = "招商银行";
    //定义静态的成员方法，通过类名访问
    static void toWelcome() {
        System.out.println("欢迎来到" + bankname+"------------");
    }
    static void end(){
        System.out.println("请携带好随身物品，欢迎下次光临"+bankname+"------------");
    }
    //有参的构造方实现开户
    Bank(String name) {
        this.name = name;
        this.balance = 100;
        System.out.println(this.name + ",你好，开户成功，账户余额," + this.balance);
    }
   //存款
    void Deposit(double money) {
        double money1 = money;
        this.moneys = this.balance + money1;
        System.out.println(this.name + ",你好，你好的账户已存入" + money1 + ",当前余额" + this.moneys);
    }
   //取款
    void Withdrawal(String password1,double money) {
        if (this.password.equals(password1)) {//判断密码是否正确
            double money1 = money;
            if (this.moneys < money1) {
                System.out.println("账户余额不足");
                return;
            }
            this.balance = this.moneys - money1;
            System.out.println(this.name + ",你好，你的账户已取出" + money1 + ",当前余额" + this.balance);
        } else {
            System.out.println("对不起，密码错误");
        }
    }

}
public class Test2{

    public static void main(String[] args){
        Bank.toWelcome();//通过类名法访问静态方法
        Bank b = new Bank("王雅钊");//开户
        b.Deposit(100);//存款
        //取款
        b.Withdrawal("1234",677);
        b.Withdrawal("123456",700);
        b.Withdrawal("123456",120);
        Bank.end();
    }
}
